package com.wgchao.identityrightsmanagement.application.controller;

import com.wgchao.identityrightsmanagement.application.service.OfficeApplicationService;
import com.wgchao.identityrightsmanagement.domain.organization.model.OfficeCreator;
import com.wgchao.identityrightsmanagement.domain.organization.model.OfficeUpdator;
import com.wgchao.identityrightsmanagement.infrastructure.utils.PageData;
import com.wgchao.identityrightsmanagement.infrastructure.utils.ResponseData;
import com.wgchao.identityrightsmanagement.query.OfficeQuery;
import com.wgchao.identityrightsmanagement.query.pageparam.OfficePageParam;
import com.wgchao.identityrightsmanagement.query.vo.OfficeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: OfficeController
 * @author: wgchao
 * @createTime: 2020/6/16 4:22 PM
 * @Description: TODO
 */
@RestController
@RequestMapping("/sntk/sys/base/office")
@Api(value = "OfficeController", description = "职位信息管理")
public class OfficeController {
    @Autowired
    private OfficeApplicationService officeApplicationService;
    @Autowired
    private OfficeQuery officeQuery;


    @ApiOperation(value = "向机构添加职位")
    @PostMapping("/{agencyCode}")
    public ResponseData addOfficeToAgency(@ApiParam(name = "agencyCode", value = "机构编号", required = true) @PathVariable String agencyCode,
                                           @ApiParam(name = "creator", value = "职位信息", required = true) @RequestBody OfficeCreator creator){
        officeApplicationService.addOffice(agencyCode, creator, "admin");
        return ResponseData.success();
    }

    @ApiOperation(value = "修改职位基本信息")
    @PutMapping("/{code}")
    public ResponseData modifyOfficeInfo(@ApiParam(name = "code", value = "职位编码", required = true) @PathVariable String code,
                                          @ApiParam(name = "updator", value = "账户信息", required = true) @RequestBody OfficeUpdator updator){
        officeApplicationService.modifyOfficeInfo(code, updator, "admin");
        return ResponseData.success();
    }

    @ApiOperation(value = "禁用职位")
    @PutMapping("/disabled/{code}")
    public ResponseData disabled(@ApiParam(name = "code", value = "职位编码", required = true) @PathVariable String code){
        officeApplicationService.disable(code, "admin");
        return ResponseData.success();
    }

    @ApiOperation(value = "启用职位")
    @PutMapping("/regain/{code}")
    public ResponseData regain(@ApiParam(name = "code", value = "职位编码", required = true) @PathVariable String code){
        officeApplicationService.regain(code, "admin");
        return ResponseData.success();
    }

    @ApiOperation(value = "删除职位")
    @DeleteMapping("/{code}")
    public ResponseData remove(@ApiParam(name = "code", value = "职位编码", required = true) @PathVariable String code){
        officeApplicationService.remove(code, "admin");
        return ResponseData.success();
    }

    @ApiOperation(value = "查询职位信息")
    @GetMapping("/{code}")
    public ResponseData<OfficeVo> findByCode(@ApiParam(name = "code", value = "职位编号", required = true) @PathVariable String code){
        OfficeVo officeVo = officeQuery.findByCode(code);
        return ResponseData.success().setData(officeVo);
    }

    @ApiOperation(value = "查询职位信息")
    @GetMapping("/page/condition")
    public ResponseData<PageData<OfficeVo>> findByConditions(@ApiParam(name = "officePageParam", value = "查询条件", required = true)
                                                                     OfficePageParam officePageParam){
        PageData<OfficeVo> officeVoPageData = officeQuery.findByConditionsWithPage(officePageParam);
        return ResponseData.success().setData(officeVoPageData);
    }

}
